<?php
session_start();
include('lib/lib.php');
include('connado.php');
//include('authen.php');
header("Content-type: text/html; charset=utf-8");
$logfile = PAHTLOG."ajax_cmdalarm-" . date("Y-m-d") . ".log";


$alarm_num = $_REQUEST['alarm_num'];
$alarm_en = $_REQUEST['alarm_en'];
$alarm_th = $_REQUEST['alarm_th'];
$chk_dup = $_REQUEST['chk_dup'];
$action = $_REQUEST['action'];

writelog($logfile, "alarm num     : " . $alarm_num);
writelog($logfile, "alarm_en      : " . $alarm_en);
writelog($logfile, "alarm_th      : " . $alarm_th);
$alarm_th = iconv('tis-620', 'utf-8', $alarm_th);
writelog($logfile, "chech duplicate : " . $chk_dup);
writelog($logfile, "action   : " . $action);

if($action == "add"){
	$sql = "insert into alarm_desc(alarm_num, alarm_desc_en, alarm_desc_th, check_dup)values(?, ?, ?, ?)";
	$stmt = $db->Prepare($sql);
	$arr_pre = array($alarm_num, $alarm_en, $alarm_th, $chk_dup);
	if($db->Execute($stmt, $arr_pre)){
		writelog($logfile, "add alarm_desc success!");
	}else{
		writelog($logfile, "add alarm_desc error!");
	}
}else if($action == "del"){
	$sql = "delete from alarm_desc where alarm_num=?";
	$stmt = $db->Prepare($sql);
	$arr_pre = array($alarm_num);
	if($db->Execute($stmt, $arr_pre)){
		writelog($logfile, "delete alarm success!");
	}else{
		writelog($logfile, "delete alarm error!");
	}
}else if($action == "edit"){
	$sql = "update province set province_desc =? where province_id=?";
	$stmt = $db->Prepare($sql);
	$arr_pre = array($prov_desc, $prov_id);
	if($db->Execute($stmt, $arr_pre)){
		writelog($logfile, "update province success!");
	}else{
		writelog($logfile, "update province error!");
	}
	
}


writelog($logfile, "reply : OK");
writelog($logfile, "-------------------------------------------------- ");
echo viewAlarm($db);

?>

